package vista;

import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.DefaultListSelectionModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.SwingUtilities;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
@SuppressWarnings("serial")
public class VentanaFacturaPrincipal extends javax.swing.JFrame {
	private JPanel pnlPrincipal;
	private JLabel lblImagen;
	private JButton btnConsultar;
	private JTable tblfactura;
	private JScrollPane jcpFactura;
	private JButton btnIncluir;
	private JLabel lblMenuFactura;

	/**
	 * Auto-generated main method to display this JFrame
	 */


	public VentanaFacturaPrincipal() {
		super();
		initGUI();
	}

	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				pnlPrincipal = new JPanel();
				getContentPane().add(pnlPrincipal, BorderLayout.CENTER);
				pnlPrincipal.setLayout(null);
				pnlPrincipal.setLayout(null);
				pnlPrincipal.setBackground(new java.awt.Color(255, 255, 255));
				pnlPrincipal.setPreferredSize(new java.awt.Dimension(753, 313));
				{
					lblMenuFactura = new JLabel();
					pnlPrincipal.add(lblMenuFactura);
					lblMenuFactura.setText("Menu de factura.");
					lblMenuFactura.setBounds(214, 16, 247, 32);
					lblMenuFactura.setFont(new java.awt.Font(
							"Bitstream Charter", 0, 22));
				}
				{
					btnIncluir = new JButton();
					pnlPrincipal.add(btnIncluir);
					btnIncluir.setBounds(207, 254, 94, 32);
					btnIncluir.setIcon(new ImageIcon(getClass()
							.getClassLoader().getResource(
									"imagen/Boton_Incluir2.jpg")));
					btnIncluir.setBorder(BorderFactory.createEmptyBorder(0, 0,
							0, 0));
					btnIncluir.setRolloverIcon(new ImageIcon(getClass()
							.getClassLoader().getResource(
									"imagen/Boton_Incluir.jpg")));
					btnIncluir.setActionCommand("Incluir");
				}
				{
					jcpFactura = new JScrollPane();
					pnlPrincipal.add(jcpFactura);
					jcpFactura.setBounds(101, 56, 422, 141);
					{
						TableModel tblfacturaModel = new DefaultTableModel(
								new String[][] {}, new String[] { "Numero",
										"Proveedor", "Fecha" });
						tblfactura = new JTable();
						jcpFactura.setViewportView(tblfactura);
						tblfactura.setModel(tblfacturaModel);
						tblfactura
								.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
					}
				}
				{
					btnConsultar = new JButton();
					pnlPrincipal.add(btnConsultar);
					btnConsultar.setBounds(307, 258, 82, 24);
					btnConsultar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Consulta2.jpg")));
					btnConsultar.setBorder(BorderFactory.createEmptyBorder(0,
							0, 0, 0));
					btnConsultar.setRolloverIcon(new ImageIcon(getClass().getClassLoader().getResource("imagen/Boton_Consulta.jpg")));
					btnConsultar.setActionCommand("Consultar");
				}
				{
					lblImagen = new JLabel();
					pnlPrincipal.add(lblImagen);
					lblImagen.setBounds(4, 12, 46, 308);
					lblImagen.setIcon(new ImageIcon(getClass().getClassLoader()
							.getResource("imagen/fondo7.jpg")));
				}
			}
			pack();
			this.setSize(648, 341);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void agregarListener(ActionListener actionListener) {
		btnIncluir.addActionListener(actionListener);
		btnConsultar.addActionListener(actionListener);
	}

	public void setTxtIngreseOpcion(JTextField txtIngreseOpcion) {
	}

	public JTable getTblfactura() {
		return tblfactura;
	}

	public void setTblfactura(JTable tblfactura) {
		this.tblfactura = tblfactura;
	}

	public int cantidadFilasDeFacturas() {
		return tblfactura.getRowCount();
	}

	public int numeroFilasSeleccionadas() {
		return tblfactura.getSelectedRowCount();
	}

	public void mostrarMensaje(String mensaje) {
		JOptionPane.showMessageDialog(this, mensaje, "Información",
				JOptionPane.INFORMATION_MESSAGE);
	}

	public String getSelectedCodigoFactura() {
		DefaultTableModel modelo = (DefaultTableModel) this.tblfactura
				.getModel();
		int fila = tblfactura.getSelectedRow();

		return (String) modelo.getValueAt(fila, 0);
	}

	public void agregarFilaFactura(Vector<String> datoFactura) {
		DefaultTableModel modelop = (DefaultTableModel) tblfactura.getModel();

		modelop.addRow(datoFactura);

	}

	public String retornarNumeroFacturaDeTabla(int index) {
		DefaultTableModel modelo = (DefaultTableModel) tblfactura.getModel();
		String numeroFactura = (String) modelo.getValueAt(index, 0);
		return numeroFactura;
	}

	public void eliminarFilaTblUbicarItemCompra(int index) {
		DefaultTableModel modelo = (DefaultTableModel) this.tblfactura
				.getModel();

		modelo.removeRow(index);
	}
}
